<?php
header("Content-Type:json/html;charset=utf8");

$config = require '../config.php';
require '../validToken.php';
$conn = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);
$info = isValidToken($conn);
if($info['status']){
    $category = $_POST['category'];

    $sql = "insert into category(category) values ('$category')";
    $result = $conn->query($sql);

    if($result){
        $result = ['code' =>1,  'msg' => "新增分类成功!"];
        require "../util/savelog.php";
        saveLog($conn, $info['user']['id'], "新增分类: $category");
    }else{
        $result = ['code' =>0,   'msg' => "新增分类失败!"];
    }
}else{
    $result = ['code' =>-1,   'msg' => "token失效!"];
}
print_r(json_encode($result));

